package com.baomidou.wechat.mp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.baomidou.wechat.mp.apistore.actuator.IpActuator;
import com.baomidou.wechat.mp.util.MatcherUtil;

/**
 * IP 归属地查询
 */
@Controller
@RequestMapping("/ip")
public class IpController extends BaseController {

	@RequestMapping(value = "/search", method = RequestMethod.GET)
	public String search(Model model) {
		return "/ip/search";
	}
	
	@RequestMapping(value = "/post", method = RequestMethod.POST)
	public String post(Model model) {
		String ip = request.getParameter("ipAddress");
		if (MatcherUtil.isIp(ip)) {
			model.addAttribute("ipVo", new IpActuator(ip).execute());
		}
		model.addAttribute("errorTip", "请输入正确的IP地址！");
		return "/ip/search";
	}

}
